package com.deram.ctin.rest.web.controller.web;

import com.deram.ctin.common.bean.Page;
import com.deram.ctin.common.bean.PageResult;
import com.deram.ctin.dependencies.rest.base.BaseController;
import com.deram.ctin.serv.business.api.*;
import com.deram.ctin.serv.business.entity.*;
import com.deram.ctin.serv.business.filter.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhangcm
 * @version 1.0, 2017/9/28
 */
@Api(tags = {"web - 企业年报接口"})
@RestController
@RequestMapping("/web/enter")
public class WebEnterAnnualInfoController extends BaseController {

    @Autowired
    private BusinessInfoApi businessInfoApi;

    @Autowired
    private BusinessDomainApi businessDomainApi;

    @Autowired
    private BusinessShareholderApi businessShareholderApi;

    @Autowired
    private BusinessInvestmentApi businessInvestmentApi;

    @Autowired
    private BusinessTransferApi businessTransferApi;

    @Autowired
    private BusinessEnterAssetsApi businessEnterAssetsApi;

    @ApiOperation(value = "工商信息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, paramType = "path")
    })
    @GetMapping("/businessInfo/{id}/{year}")
    public BusinessInfo businessInfo(@PathVariable Long id, @PathVariable Integer year){
        return businessInfoApi.findByYear(id, year);
    }

    @ApiOperation(value = "网站信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, paramType = "path")
    })
    @GetMapping("/domain/{id}/{year}")
    public PageResult<BusinessDomain> domain(@PathVariable Long id, @PathVariable Integer year, Page page){
        BusinessDomainFilter filter = new BusinessDomainFilter();
        filter.setEnterId(id);
        filter.setYear(year);
        filter.setHasYear(true);
        return businessDomainApi.search(filter, page.getPageNo(), page.getPageSize());
    }

    @ApiOperation(value = "股东信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, paramType = "path")
    })
    @GetMapping("/shareholder/{id}/{year}")
    public PageResult<BusinessShareholder> shareholder(@PathVariable Long id, @PathVariable Integer year, Page page){
        BusinessShareholderFilter filter = new BusinessShareholderFilter();
        filter.setEnterId(id);
        filter.setYear(year);
        filter.setHasYear(true);
        return businessShareholderApi.search(filter, page.getPageNo(), page.getPageSize());
    }

    @ApiOperation(value = "对外投资")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, paramType = "path")
    })
    @GetMapping("/investment/{id}/{year}")
    public PageResult<BusinessInvestment> investment(@PathVariable Long id, @PathVariable Integer year, Page page){
        BusinessInvestmentFilter filter = new BusinessInvestmentFilter();
        filter.setEnterId(id);
        filter.setYear(year);
        filter.setHasYear(true);
        return businessInvestmentApi.searchWithEnter(filter, page.getPageNo(), page.getPageSize());
    }

    @ApiOperation(value = "股权转让")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, paramType = "path")
    })
    @GetMapping("/transfer/{id}/{year}")
    public PageResult<BusinessTransfer> transfer(@PathVariable Long id, @PathVariable Integer year, Page page){
        BusinessTransferFilter filter = new BusinessTransferFilter();
        filter.setEnterId(id);
        filter.setYear(year);
        filter.setHasYear(true);
        return businessTransferApi.search(filter, page.getPageNo(), page.getPageSize());
    }

    @ApiOperation(value = "企业资产")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "ID", required = true, paramType = "path"),
            @ApiImplicitParam(name = "year", value = "年份", required = true, paramType = "path")
    })
    @GetMapping("/enterAssets/{id}/{year}")
    public BusinessEnterAssets enterAssets(@PathVariable Long id, @PathVariable Integer year){
        return businessEnterAssetsApi.findByYear(id, year);
    }
}
